﻿using ERPWinFormWork.Produce.ErrorCode;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static ERPWinFormWork.Produce.Dispatch_WorkForm;

namespace ERPWinFormWork.Produce
{
    public partial class Reporting_WorkFrom : Form
    {
        public bool IsOperationCompleteds { get; internal set; }
        private ApiClient _apiClient;
        public Reporting_WorkFrom()
        {
            InitializeComponent();
            // 初始化 API 客户端（替换为你的实际 API 基础地址）
            _apiClient = new ApiClient(AppConfig.ApiBaseUrl);
        }

        public class CreateReporting_Work
        {
            /// <summary>
            /// 报工数量
            /// </summary>
            public string Number_Applications { get; set; }
            
        }

        private async void btnsubmit_Click(object sender, EventArgs e)
        {
            // 构建请求实体对象，将窗体控件值赋值给实体属性
            var requestModel = new CreateReporting_Work
            {
                Number_Applications = txtNumber_Applications.Text.Trim(),
                
            };
            var response = await _apiClient.PostAsync<CreateReporting_Work, ApiResponse<string>>(
                endpoint: "Production_Plan/CreateReporting_WorkHandle",
                data: requestModel
            );
            if (response.code == 200)
            {
                // 这里可根据后端返回的结果做相应处理，比如简单提示成功
                MessageBox.Show("报工完成");
                // 可选择清空窗体控件内容，准备下次添加
                ClearControls();
                IsOperationCompleteds = true;

                this.Close();
            }
            else
            {
                MessageBox.Show("报工失败");
            }
        }
        // 清空窗体控件内容的方法，按需使用
        private void ClearControls()
        {
            txtNumber_Applications.Clear();


        }
    }
}
